#include <iostream>
#include <string>
#include <stack>
#include <memory.h>
#include <string.h>

static bool is_lower_alphanum(char c)
{
    return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'z');
}

static bool is_hex(char c)
{
    return (c >= '0' && c <= '9') 
        || (c >= 'A' && c <= 'F') 
        || (c >= 'a' && c <= 'f');
}

static bool is_valid_escape(const char *s, size_t len)
{
    if (len < 4)
        return false;
    if (memcmp(s, "&lt;", 4) == 0)
        return true;
    if (memcmp(s, "&gt;", 4) == 0)
        return true;
    if (len < 5)
        return false;
    if (memcmp(s, "&amp;", 5) == 0)
        return true;
    if (len % 2 != 1 || s[1] != 'x')
        return false;
    for (size_t i = 2; i < len - 1; i++)
        if (!is_hex(s[i]))
            return false;
    return true;
}

typedef std::pair<const char *,size_t> tag_position; /* (str, len) */
static std::stack<tag_position> tag_stack;

static bool is_valid_tag(const char *s)
{
    size_t i = (s[1] == '/')? 2 : 1; /* start of tag name */
    size_t j;
    for (j = i; is_lower_alphanum(s[j]); j++);
    if (j == i)
        return false;

    if (s[j] == '>')
    {
        if (i == 1)             /* open tag */
        {
            tag_stack.push(tag_position(s+i, j-i));
            return true;
        }

        if (tag_stack.empty())  /* close tag without open tag */
            return false;
        
        tag_position last = tag_stack.top();
        tag_stack.pop();
        size_t len = last.second;
        if (len != j - i)       /* tag length mismatch */
            return false;
        if (memcmp(last.first, s + i, len) != 0)    /* tag mismatch */
            return false;
        return true;
    }

    if (s[j] == '/')    /* self-closed tag */
    {
        return s[j+1] == '>';
    }

    return false;       /* non-alphanumeric tag name */
}

static bool is_valid_xml(const char *s)
{
    while (!tag_stack.empty())
        tag_stack.pop();
   
    for (size_t i = 0; s[i]; i++)
    {
        char c = s[i];
        if (c == '&')
        {
            const char *t = strchr(s + i, ';');
            if (!t)             /* '&' without ';' */
                return false;
            size_t j = t - s;
            if (!is_valid_escape(s + i, j - i + 1))
                return false;
            i = j;
            continue;
        }
        if (c == '<')
        {
            const char *t = strchr(s + i, '>');
            if (!t)     /* no matching '>' */
                return false;
            size_t j = t - s;
            if (!is_valid_tag(s + i))
                return false;
            i = j;
            continue;
        }
        if (c == '>')
            return false;
        if (c >= 32 && c <= 127)
            continue;
        return false;
    }
    if (!tag_stack.empty())
        return false;
    else
        return true;
}

int main()
{
    std::ios_base::sync_with_stdio(false);
    std::string line;
    while (std::getline(std::cin, line))
    {
        if (is_valid_xml(line.c_str()))
            std::cout << "valid" << std::endl;
        else
            std::cout << "invalid" << std::endl;
    }
    return 0;
}